<template>
  <div>
    <header>
      <h3>{{data.title}}</h3>
      <div>
        <span>{{data.author}} </span>
        <span>{{data.time}} </span>
        <span>
          <label>{{data.count}}</label>次围观</span>
      </div>
    </header>
    <div id="content">
      <ul>
        <li v-for="item in data.img">
          <img v-bind:src="domain+item.src" />
        </li>
      </ul>
      <div class="main-bottom">
        <img src="../assets/img/end.png" />
        <p>Powered by
          <a style="color: #064992;text-decoration: none;" href="//www.cvtouch.com" target="_blank">CVTOUCH </a>
        </p>
        <p>Copyright 2009-2017 广州视源电子科技股份有限公司</p>
      </div>
    </div>
    <footer>

      <div class="c-bottom top">
        <img src="../assets/img/top.png" alt="向上" v-on:click="top" />
        <label>4/4</label>
      </div>
      <div class="c-bottom qr">
        <img src="../assets/img/qr.png" alt="二维码" v-on:click.stop="lock" />
        <label>二维码</label>
      </div>
      <div class="c-bottom dl">
        <img src="../assets/img/save.png" alt="下载" />
        <label>下载</label>
      </div>
    </footer>
    <div id="qrScreen">
      <div>
        <img src="../assets/img/code.png" />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  data () {
    return {
      data: {
        'id': 0,
        'title': '',
        'author': '',
        'time': '',
        'count': 0,
        'img': [],
        'code-img': ''

      },
      domain: 'http://localhost:3000/'
    }
  },
  methods: {
    getData: function (id) {
      // let vm = this
      this.$http.get(`api/${id}`).then((response) => {
        // var json = JSON.parse(response.body)
        // console.log(response)
        this.data = response.body.data
        // this.data = Object.assign({}, this.data, response.body.data)
        // vm.$set(vm.data, 'title', response.body.data.title)
        // vm.$set(vm.data, response.body.data)
        console.log('change')
        console.log(this.data)
      }, (response) => {
        console.log('error')
        console.log(response)
      })
    },
    getParams: function () {
      let url = location.href
      let id = url.substring(url.indexOf('?')).split('=')[1]
      return id
    },
    lock: function () {
      var screen = document.getElementById('qrScreen')
      screen.classList.add('active')
      document.onclick = function () {
        screen.classList.remove('active')
        this.onclick = null
      }
      console.log('lock', screen)
    },
    top: function () {
      document.documentElement.scrollTop = document.body.scrollTop = 0
    }
  },
  created () {
    let id = this.getParams()
    console.log(id)
    this.getData(id)
    console.log('mounted')
    console.log(this.data)
  }
  // beforeRouteEnter (to, from, next) {
  //   next(vm => {
  //     console.log(11111)
  //   })
  // },
  // watch: {
  //   'data': function () {
  //     console.log('data change')
  //   }
  // }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
* {
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
}





/* flex布局设置 */

body {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  /*overflow: hidden;*/
}





/* header部分*/

header {
  height: 75px;
  background-color: #064992;
  padding: 15px 20px 10px 15px;
  color: white;
}

header>h3 {
  font-size: 18px;
  width: 100%;
  height: 25px;
  overflow: hidden;
  text-overflow: ellipsis;
}

header>div>span {
  font-size: 12px;
  margin-right: 5px;
}





/* 主体内容部分 */

#content {
  flex: 1;
  padding: 10px 5px;
  border: 1px solid #CCC;
  border-top: 0;
  background: #f9f9f9;
}





/* #content ul {} */

#content ul li {
  list-style-type: none;
  margin: 10px 0;
  box-shadow: 0 1px 5px #BBB;
  width: 100%;
  overflow: hidden;
}

#content ul li img {
  display: block;
  width: 100%;
}

.main-bottom {
  width: 100%;
  color: #888;
  box-sizing: border-box;
  text-align: center;
  font-size: 12px;
  background-color: white;
  margin-top: 10px;
}

.main-bottom p {
  margin-bottom: 10px;
}

.main-bottom>img {
  width: 100%;
  margin-bottom: 10px;
}

.main-bottom:after {
  content: '.';
  display: block;
  height: 46px;
  visibility: hidden;
}





/* 底部 */

footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  color: #666;
  box-sizing: border-box;
  background-color: #f2f2f2;
  height: 48px;
  box-shadow: 0 1px 3px #666;
  text-align: center;
}

footer>div {
  display: inline-block;
  width: 33.333%;
  box-sizing: border-box;
  margin-left: -4px
}

footer img {
  width: 20px;
  height: 20px;
  display: block;
  margin: 6px auto;
}

footer label {
  display: block;
  color: #888;
  font-size: 10px;
  font-weight: 600;
  line-height: 13px;
  height: 13px;
}





/* 二维码部分 */

#qrScreen {
  opacity: 0;
  visibility: hidden;
  height: 100%;
  width: 100%;
  -webkit-transition-duration: .4s;
  transition-duration: .4s;
  background-color: rgba(0, 0, 0, 0.4);
}

#qrScreen.active {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
  opacity: 1;
  visibility: visible;
}

#qrScreen>div {
  width: 190px;
  height: 190px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

#qrScreen>div>img {
  display: block;
  width: 100%;
  width: 100%;
}
</style>
